package javolution.util;

import java.util.Comparator;
import javolution.lang.Configurable;
import javolution.text.Text;
import javolution.xml.XMLSerializable;
import org.apache.http.protocol.HTTP;

/* loaded from: classes2.dex */
public abstract class FastComparator<T> implements Comparator<T>, XMLSerializable {
    public static final Configurable<Boolean> REHASH_SYSTEM_HASHCODE = new Configurable(isPoorSystemHash()) { // from class: javolution.util.FastComparator.1
        @Override // javolution.lang.Configurable
        protected void notifyChange() {
            FastComparator._Rehash = ((Boolean) get()).booleanValue();
        }
    };
    static boolean _Rehash = REHASH_SYSTEM_HASHCODE.get().booleanValue();
    public static final FastComparator<Object> DEFAULT = new Default();
    public static final FastComparator<Object> DIRECT = new Direct();
    public static final FastComparator<Object> REHASH = new Rehash();
    public static final FastComparator<Object> IDENTITY = new Identity();
    public static final FastComparator<CharSequence> LEXICAL = new Lexical();

    /* loaded from: classes2.dex */
    static final class Default extends FastComparator {
        Default() {
        }

        @Override // javolution.util.FastComparator
        public boolean areEqual(Object obj, Object obj2) {
            if (obj == null) {
                if (obj2 != null) {
                    return false;
                }
            } else if (obj != obj2 && !obj.equals(obj2)) {
                return false;
            }
            return true;
        }

        @Override // javolution.util.FastComparator, java.util.Comparator
        public int compare(Object obj, Object obj2) {
            return ((Comparable) obj).compareTo(obj2);
        }

        @Override // javolution.util.FastComparator
        public int hashCodeOf(Object obj) {
            return _Rehash ? REHASH.hashCodeOf(obj) : obj.hashCode();
        }

        public String toString() {
            return "default";
        }
    }

    /* loaded from: classes2.dex */
    static final class Direct extends FastComparator {
        Direct() {
        }

        @Override // javolution.util.FastComparator
        public boolean areEqual(Object obj, Object obj2) {
            if (obj == null) {
                if (obj2 != null) {
                    return false;
                }
            } else if (obj != obj2 && !obj.equals(obj2)) {
                return false;
            }
            return true;
        }

        @Override // javolution.util.FastComparator, java.util.Comparator
        public int compare(Object obj, Object obj2) {
            return ((Comparable) obj).compareTo(obj2);
        }

        @Override // javolution.util.FastComparator
        public int hashCodeOf(Object obj) {
            return obj.hashCode();
        }

        public String toString() {
            return "direct";
        }
    }

    /* loaded from: classes2.dex */
    static final class Identity extends FastComparator {
        Identity() {
        }

        @Override // javolution.util.FastComparator
        public boolean areEqual(Object obj, Object obj2) {
            return obj == obj2;
        }

        @Override // javolution.util.FastComparator, java.util.Comparator
        public int compare(Object obj, Object obj2) {
            return ((Comparable) obj).compareTo(obj2);
        }

        @Override // javolution.util.FastComparator
        public int hashCodeOf(Object obj) {
            int identityHashCode = System.identityHashCode(obj);
            if (_Rehash) {
                int i = identityHashCode + ((identityHashCode << 9) ^ (-1));
                int i2 = i ^ (i >>> 14);
                int i3 = i2 + (i2 << 4);
                return i3 ^ (i3 >>> 10);
            }
            return identityHashCode;
        }

        public String toString() {
            return HTTP.IDENTITY_CODING;
        }
    }

    /* loaded from: classes2.dex */
    static final class Lexical extends FastComparator {
        Lexical() {
        }

        @Override // javolution.util.FastComparator
        public boolean areEqual(Object obj, Object obj2) {
            boolean z = obj instanceof String;
            if (z && (obj2 instanceof String)) {
                return obj.equals(obj2);
            }
            if ((obj instanceof CharSequence) && (obj2 instanceof String)) {
                CharSequence charSequence = (CharSequence) obj;
                String str = (String) obj2;
                int length = str.length();
                if (charSequence.length() != length) {
                    return false;
                }
                int i = 0;
                while (i < length) {
                    int i2 = i + 1;
                    if (str.charAt(i) != charSequence.charAt(i)) {
                        return false;
                    }
                    i = i2;
                }
                return true;
            } else if (z && (obj2 instanceof CharSequence)) {
                CharSequence charSequence2 = (CharSequence) obj2;
                String str2 = (String) obj;
                int length2 = str2.length();
                if (charSequence2.length() != length2) {
                    return false;
                }
                int i3 = 0;
                while (i3 < length2) {
                    int i4 = i3 + 1;
                    if (str2.charAt(i3) != charSequence2.charAt(i3)) {
                        return false;
                    }
                    i3 = i4;
                }
                return true;
            } else if (obj == null || obj2 == null) {
                return obj == obj2;
            } else {
                CharSequence charSequence3 = (CharSequence) obj;
                CharSequence charSequence4 = (CharSequence) obj2;
                int length3 = charSequence3.length();
                if (charSequence4.length() != length3) {
                    return false;
                }
                int i5 = 0;
                while (i5 < length3) {
                    int i6 = i5 + 1;
                    if (charSequence3.charAt(i5) != charSequence4.charAt(i5)) {
                        return false;
                    }
                    i5 = i6;
                }
                return true;
            }
        }

        @Override // javolution.util.FastComparator, java.util.Comparator
        public int compare(Object obj, Object obj2) {
            int i = 0;
            if (obj instanceof String) {
                String str = (String) obj;
                if (obj2 instanceof String) {
                    return str.compareTo((String) obj2);
                }
                CharSequence charSequence = (CharSequence) obj2;
                int min = Math.min(str.length(), charSequence.length());
                while (true) {
                    int i2 = min - 1;
                    if (min == 0) {
                        return str.length() - charSequence.length();
                    }
                    char charAt = str.charAt(i);
                    int i3 = i + 1;
                    char charAt2 = charSequence.charAt(i);
                    if (charAt != charAt2) {
                        return charAt - charAt2;
                    }
                    min = i2;
                    i = i3;
                }
            } else if (obj2 instanceof String) {
                return -compare(obj2, obj);
            } else {
                CharSequence charSequence2 = (CharSequence) obj;
                CharSequence charSequence3 = (CharSequence) obj2;
                int min2 = Math.min(charSequence2.length(), charSequence3.length());
                while (true) {
                    int i4 = min2 - 1;
                    if (min2 == 0) {
                        return charSequence2.length() - charSequence3.length();
                    }
                    char charAt3 = charSequence2.charAt(i);
                    int i5 = i + 1;
                    char charAt4 = charSequence3.charAt(i);
                    if (charAt3 != charAt4) {
                        return charAt3 - charAt4;
                    }
                    min2 = i4;
                    i = i5;
                }
            }
        }

        @Override // javolution.util.FastComparator
        public int hashCodeOf(Object obj) {
            if ((obj instanceof String) || (obj instanceof Text)) {
                return obj.hashCode();
            }
            CharSequence charSequence = (CharSequence) obj;
            int length = charSequence.length();
            int i = 0;
            for (int i2 = 0; i2 < length; i2++) {
                i = (i * 31) + charSequence.charAt(i2);
            }
            return i;
        }

        public String toString() {
            return "lexical";
        }
    }

    /* loaded from: classes2.dex */
    static final class Rehash extends FastComparator {
        Rehash() {
        }

        @Override // javolution.util.FastComparator
        public boolean areEqual(Object obj, Object obj2) {
            if (obj == null) {
                if (obj2 != null) {
                    return false;
                }
            } else if (obj != obj2 && !obj.equals(obj2)) {
                return false;
            }
            return true;
        }

        @Override // javolution.util.FastComparator, java.util.Comparator
        public int compare(Object obj, Object obj2) {
            return ((Comparable) obj).compareTo(obj2);
        }

        @Override // javolution.util.FastComparator
        public int hashCodeOf(Object obj) {
            int hashCode = obj.hashCode();
            int i = hashCode + ((hashCode << 9) ^ (-1));
            int i2 = i ^ (i >>> 14);
            int i3 = i2 + (i2 << 4);
            return i3 ^ (i3 >>> 10);
        }

        public String toString() {
            return "rehash";
        }
    }

    private static Boolean isPoorSystemHash() {
        boolean[] zArr = new boolean[32];
        for (int i = 0; i < zArr.length; i++) {
            zArr[new Object().hashCode() & (zArr.length - 1)] = true;
        }
        int i2 = 0;
        for (boolean z : zArr) {
            if (!z) {
                i2++;
            }
        }
        return new Boolean(i2 > (zArr.length >> 1));
    }

    public abstract boolean areEqual(T t, T t2);

    @Override // java.util.Comparator
    public abstract int compare(T t, T t2);

    public abstract int hashCodeOf(T t);
}
